package main

import (
	"fmt"
	"os"
	"path"
)

type File string

func (f File) File() string {
	return string(f)
}

func (f File) String() string {
	return string(f)
}

func (f File) GetPath() string {
	return f.String()
}

func (f File) GetBasePath() string {
	return path.Base(f.GetPath())
}

func (f File) GetExt() string {
	return path.Ext(f.GetPath())
}

func (f File) GetState() (os.FileInfo, error) {
	return os.Stat(f.GetPath())
}

func (f File) GetExists() bool {
	_, err := f.GetState()
	if err != nil {
		if os.IsNotExist(err) {
			return false
		}
	}
	return true
}

func (f File) IsDir() (bool, error) {
	if !f.GetExists() {
		return false, fmt.Errorf("no files or directories: %v", f.GetPath())
	}
	stat, _ := f.GetState()
	return stat.IsDir(), nil
}

func (f File) IsFile() (bool, error) {
	dir, err := f.IsDir()
	if err != nil {
		return false, err
	}
	return !dir, nil
}

func (f File) IsSymlink() bool {
	return false
}

func main() {
	file := File(os.Args[0])

	fmt.Println("file:", file)
	fmt.Println("String:", file.String())
	fmt.Println("GetExt:", file.GetExt())
	fmt.Println("GetPath:", file.GetPath())
	fmt.Println("GetBasePath", file.GetBasePath())
	fmt.Println("GetExists:", file.GetExists())
	isdir, _ := file.IsDir()
	isfile, _ := file.IsFile()
	fmt.Println("isdir: ", isdir)
	fmt.Println("isfile: ", isfile)
	fmt.Println("GetPath", file.GetPath())
}
